<?php
require_once("classes\class.RadTemplate.php");

/**
 *
 *
 */
interface IPage {
	public function render();
}


/**
 *
 *
 */
abstract class Page extends Property implements IPage {
	protected $_eng;
	protected $_template_file;
	protected $_action;
	protected $_page;
	/**
	 * Constructor
	 * @access protected
	 */
	public function __construct() {
		$this->_eng = new RadEngine();
		$this->_eng->setInfo(TRUE);
		$this->properties = array(
			"TemplateFile" => NULL,
			"Page" => NULL,
			"Action" => NULL
		);
	}

	public function __destruct() {
		if ($this->_eng != NULL && !isset($this->_eng)) {
			unset($this->_eng);
			$this->_eng = NULL;
		}
	}

	public function getTemplateFile() {
		return $this->_template_file;
	}

	public function setTemplateFile($value) {
		$this->_template_file = $value;
	}

	public function getPage() {
		return $this->_page;
	}

	public function setPage($value) {
		$this->_page = $value;
	}

	public function getAction() {
		return $this->_action;
	}

	public function setAction($value) {
		$this->_action = $value;
	}

	protected function requestPage() {
		if (isset($_GET["page"]))
			return trim($_GET["page"]);
		else if (isset($_POST["page"]))
			return trim($_POST["page"]);
		else
			return NULL;
	}

	public function render() {
		$this->_eng->show($this->_template_file);
	}

	abstract protected function process();
}


class TaskPage extends Page {
	public function __construct() {
		parent::__construct();
		$this->process();
	}

	protected function process() {
		$this->_eng->assign("pagetitle", "Task List");
		if ($this->requestPage() !== NULL)
			$this->_page = $this->requestPage();
		else
			$this->_page = "Tasks";
		if (strcasecmp($this->_page, "newtask") === 0) {
			$this->_eng->assign("pagetitle", "Create New Task");
			$this->_eng->assign("task_id", "");
			$this->_eng->assign("task_name", "");
			$this->_eng->assign("task_email", "");
			$this->_eng->assign("task_desc", "");
			$this->_eng->assign("task_notes", "");
			$this->_eng->assign("task_done", "");
		}
		$this->_eng->assign("Page", $this->_page);
		$this->_template_file = "tpl/tasks.html";
	}
}

$page = new TaskPage();
$page->render();
?>